package com.cgw.auth.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cgw.auth.entity.AuthorizeInfo;
import com.cgw.auth.entity.params.BackAuthQuery;
import com.cgw.auth.service.AuthorizeInfoService;
import lombok.RequiredArgsConstructor;
import org.gavin.core.annotation.LogRecord;
import org.gavin.core.domain.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author grl
 * @since 2024-04-26
 */
@RestController
@RequiredArgsConstructor
public class AuthorizeInfoController {

    private final AuthorizeInfoService infoService;

    /**
     * 保存\修改授权接入信息
     * @return
     */
    @LogRecord(description = "保存、修改授权接入信息")
    @PostMapping(value = "/auth/save")
    public R<Boolean> saveAuth(@RequestBody @Validated AuthorizeInfo info){
        return R.ok(infoService.saveAuth(info));
    }

    /**
     *  获取Auth 的详情
     * @return
     */
    @LogRecord(description = "通过id获取Auth 的详情")
    @GetMapping(value = "/auth/detail")
    public R<AuthorizeInfo> getAuthDetail(@RequestParam(value = "id") Long id){
        return R.ok(infoService.getAuthDetail(id));
    }

    /**
     * 分页条件获取Auth 的列表
     * @return
     */
    @LogRecord(description = "分页条件获取Auth 的列表")
    @PostMapping(value = "/auth/list")
    public R<Page<AuthorizeInfo>> getAuthList(@RequestBody BackAuthQuery query){
        return R.ok(infoService.getAuthList(query));
    }

    /**
     * 通过appKey获取授权信息
     * @return
     */
    @LogRecord(description = "通过appKey获取授权信息")
    @GetMapping(value = "/auth/info")
    public R<AuthorizeInfo> getAuth(@RequestParam(value = "appKey") String appKey){
        return R.ok(infoService.getAuth(appKey));
    }
}

